clear all
clear matrix
set more off, perm
cd "D:/Data/ProjData/Organizations, political participation/mod/"
do "C:/Userdata/Shared/Dofiles/DoData/Organizations, political participation/programs.do"

capture log close
log using "C:/Userdata/Shared/Logs/Organizations, political participation/extra.text", replace text 

**************************************************************************************************************
* This dofiles contains auxcilliary analyses that were presented to reviewers, but were included in the paper*
**************************************************************************************************************

********************************************************************************
// Macros
********************************************************************************

* Variable macros
global cov 		"yearseducation socialbidragfamilj sysselsatt age gender immig zLoneInk"
global covpanel "yearseducation socialbidragfamilj sysselsatt age zLoneInk"
global covpanelsplit "yearseducation socialbidragfamilj sysselsatt zLoneInk"

* Output macros
#delimit ;
global textable		se nonotes nogaps star(* 0.10 ** 0.05 *** 0.01) label replace b(3) booktabs alignment(D{.}{.}{-1}) compress mlabels() eqlabels(none);
global robustnote	addnote("Robust standard errors in parenthesis. * p<0.1, ** p<0.05, *** p<0.01");
global robustainote	addnote("Robust Abadie--Imbens standard errors in parenthesis. * p<0.1, ** p<0.05, *** p<0.01");
global clusternote	addnote("Clustered robust standard errors on the individual level in parenthesis." "* p<0.1, ** p<0.05, *** p<0.01");
global stats1		stats(icovs data r2_a N, 
						label("Covariates?" "Time dimension data?" "Adjusted R2" "Observations") 
						fmt(0 0 3 0 %11.0fc) 
						layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")
					);
global stats2		stats(icovs ifix yfix data r2_a N, 
						label("Covariates?" "Individual fixed effects?" "Time period fixed effects?" "Time dimension data?" "Adjusted R2" "Observations") 
						fmt(0 0 0 0 3 0 %11.0fc) 
						layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")
					);
global stats3		stats(sample N, 
						label("Sample" "Observations") 
						fmt(0 %11.0fc) 
						layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")
					);					
global bothtitles 	mtitles("Turnout EP" "Turnout EP" "PP factor score" "PP factor score");
global bothtitles6c	mtitles("Turnout EP" "Turnout EP" "Turnout EP" "PP factor score" "PP factor score" "PP factor score");
global indextitle 	mtitles("Index pol.part" "Index pol.part");
global eptitles		mtitles("Turnout EP" "Turnout EP" "Turnout EP" "Turnout EP");
global factortitles mtitles("PP factor score" "PP factor score" "PP factor score" "PP factor score");	
global separatetitle mtitles("Con Muni.of" "L.Comment" "L.appeal" "L.Demon" "L.Other" "Comment" "Appeal" "Demon");	
#delimit cr

* IV analysis for response letter*
use "dataanalysis_turnout", clear

replace invkm2 = (invkm2 / 100)
label var invkm2 "100 inh./km2"

eststo clear
eststo: reg turnout_eu Nmemberships, robust 
estadd local icovs "No"
estadd local data "Pooled data"
estadd local typea "OLS"
estadd local ftest ""

eststo: reg turnout_eu invkm2, robust 
estadd local icovs "No"
estadd local data "Pooled data"
estadd local typea "Reduced form"
estadd local ftest ""

eststo: reg Nmemberships invkm2, robust 
test invkm2 = 0
estadd local icovs "No"
estadd local data "Pooled data"
estadd local typea "First stage"
local ftest = `r(F)'
estadd local ftest "`ftest'"

eststo: ivreg2 turnout_eu (Nmemberships=invkm2), robust  
estadd local icovs "No"
estadd local data "Pooled data"
estadd local typea "2SLS"
estadd local ftest ""

esttab, se star(* 0.10 ** 0.05 *** 0.01)
esttab using "C:/Userdata/Shared/Output/Organizations, political participation/table_iv1.tex", se nonotes nogaps star(* 0.10 ** 0.05 *** 0.01) mtitle("Turnout EU" "Turnout EU" "N.memberships" "Turnout EU") stats(icovs data typea ftest N, label("Covariates?" "Time dimension data?" "Analysis type" "F-test" "Observations") fmt(0 0 0 0 %11.0fc) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")) keep(Nmemberships invkm2) addnote("Robust standard errors in parenthesis. * p<0.1, ** p<0.05, *** p<0.01") label replace


***
destring LopNr period, replace
tabulate period, gen(y)
xtset LopNr period

eststo clear
eststo: xtreg turnout_eu Nmemberships y2, fe cluster(LopNr)
estadd local icovs "No"
estadd local data "Panel data"
estadd local typea "OLS"
estadd local ftest ""

eststo: xtreg turnout_eu invkm2 y2, fe cluster(LopNr)
estadd local icovs "No"
estadd local data "Panel data"
estadd local typea "Reduced form"
estadd local ftest ""

eststo: xtreg Nmemberships invkm2 y2, fe cluster(LopNr)
test invkm2 = 0
estadd local icovs "No"
estadd local data "Panel data"
estadd local typea "First stage"
local ftest = `r(F)'
estadd local ftest "`ftest'"

eststo: xtivreg2 turnout_eu (Nmemberships=invkm2) y2, fe cluster(LopNr)  
estadd local icovs "No"
estadd local data "Panel data"
estadd local typea "2SLS"
estadd local ftest ""

esttab, se star(* 0.10 ** 0.05 *** 0.01)
esttab using "C:/Userdata/Shared/Output/Organizations, political participation/table_iv2.tex", se nonotes nogaps star(* 0.10 ** 0.05 *** 0.01) mtitle("Turnout EU" "Turnout EU" "N.memberships" "Turnout EU") stats(icovs data typea ftest N, label("Covariates?" "Time dimension data?" "Analysis type" "F-test" "Observations") fmt(0 0 0 0 %11.0fc) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")) keep(Nmemberships invkm2) addnote("Robust standard errors in parenthesis. * p<0.1, ** p<0.05, *** p<0.01") label replace
eststo clear


* Political interest (bad control, but to use in answer to R3) *

* With covariates*
use "dataanalysis_turnout", clear
merge 1:1 LopNr ulfyear using "polintULF.dta", nogen keep(1 3) keepusing(poldisc)
eststo: reg turnout_eu memberany activeany $cov poldisc, robust 
	estadd local icovs "Yes"
	estadd local data "Pooled data"
eststo: reg turnout_eu Nmemberships Nactive $cov poldisc, robust 
	estadd local icovs "Yes"
	estadd local data "Pooled data"
use "dataanalysis_otherparticipation", clear
merge 1:1 LopNr ulfyear using "polintULF.dta", nogen keep(1 3) keepusing(poldisc)
eststo: reg factor memberany activeany $cov poldisc, robust 
	estadd local icovs "Yes"
	estadd local data "Pooled data"
eststo: reg factor Nmemberships Nactive $cov poldisc, robust 
	estadd local icovs "Yes"
	estadd local data "Pooled data"
esttab, se star(* 0.10 ** 0.05 *** 0.01) keep(*member* *active* poldisc) b(3)
esttab using "C:/Userdata/Shared/Output/Organizations, political participation/table2_cov_poldisc.tex", $textable $stats1 $bothtitles $robustnote keep(_cons memberany activeany Nmemberships Nactive poldisc) order(memberany activeany Nmemberships Nactive poldisc)
eststo clear


*Panel analysis: 
use "dataanalysis_turnout", clear
merge 1:1 LopNr ulfyear using "polintULF.dta", nogen keep(1 3) keepusing(poldisc)
destring LopNr period, replace
tabulate period, gen(y)
xtset LopNr period
eststo: xtreg turnout_eu memberany activeany y2 $covpanel poldisc, fe cluster(LopNr) 
	estadd local icovs "Yes"
	estadd local data "Panel"
	estadd local ifix "Yes"
	estadd local yfix "Yes"
eststo: xtreg turnout_eu Nmemberships Nactive y2 $covpanel poldisc, fe cluster(LopNr)
	estadd local icovs "Yes"
	estadd local data "Panel"
	estadd local ifix "Yes"
	estadd local yfix "Yes"
use "dataanalysis_otherparticipation", clear
merge 1:1 LopNr ulfyear using "polintULF.dta", nogen keep(1 3) keepusing(poldisc)
destring LopNr period, replace
tabulate period, gen(y)
xtset LopNr period
eststo: xtreg factor memberany activeany y2 $covpanel poldisc, fe cluster(LopNr) 
	estadd local icovs "Yes"
	estadd local data "Panel"
	estadd local ifix "Yes"
	estadd local yfix "Yes"
eststo: xtreg factor Nmemberships Nactive y2 $covpanel poldisc, fe cluster(LopNr)
	estadd local icovs "Yes"
	estadd local data "Panel"
	estadd local ifix "Yes"
	estadd local yfix "Yes"
esttab, se star(* 0.10 ** 0.05 *** 0.01) keep(*member* *active* poldisc) b(3)
esttab using "C:/Userdata/Shared/Output/Organizations, political participation/table3_panel_poldisc.tex", $textable $stats2 $bothtitles $clusternote keep(_cons memberany activeany Nmemberships Nactive poldisc) order(memberany activeany Nmemberships Nactive poldisc)
eststo clear

*******
capture log close
clear all
